#include <iostream>
#include <vector>

struct TreeNode
{
    int val;
    TreeNode* left;
    TreeNode* right;
};

class Solution {
private:
    int count;

    void _pathSum(TreeNode* root, int targetSum, std::vector<long long> nums)
    {
        if(root == nullptr)
           return;

        //插入元素
        nums.push_back(root->val + nums.back());
        //判断是否满足情况
        for(int i = 0; i < nums.size() - 1; i++)
        {
            if(nums[nums.size() - 1] - nums[i] == targetSum)
            {
                std::cout << root->val << std::endl;
                count++;
            }
        }

        //向下递归
        _pathSum(root->left, targetSum, nums);
        _pathSum(root->right, targetSum, nums);
    }   
public:
    int pathSum(TreeNode* root, int targetSum) {
        std::vector<long long> nums;
        nums.push_back(0);
        _pathSum(root, targetSum, nums);

        return count;
    }
};

//注意取值范围，是否溢出